<?php
// panel config
$panelsettings = Zend_Json::decode($this->panel->settings);
$width = $panelsettings['width'];
$align = $panelsettings['align'];

// get the associated unit details
$unit_id = $this->unit->id;
//TODO: change this to configurable value
$limit = 5;
$excursionModel = new RM_ExcursionType();
$units = $excursionModel->getAllExcursionUnits($limit);
if ($units) {$units = $units->toArray();}
// image
$imageFileModel = new RM_UnitMediaFiles();
$unitModel = new RM_Units();
$unitLangModel = new RM_UnitLanguageDetails();
$language = RM_Environment::getInstance()->getLocale();
$thumbnailImage = null;

// handle groups
if ( !$this->unit->getGroupID() ){
    $isGroup = false;
} else {
    $isGroup = true;
}

?>
<div id="<?php echo $this->panel->getDivID() ?>">
    <div class="RM_unit_details_associated_excursion_container" style="text-align:<?php echo $panelsettings['align'];?>">
            <fieldset><legend><?php echo $this->_translate->_('User.Excursion.Details','PanelTitle');?></legend>
            <div class="RM_unit_details_associated_excursion">
                <?php
                foreach($units as $unit){

                    $unitObj = $unitModel->get($unit["id"], $language);
                    // unit details
                    //$details = $unitLangModel->fetchByUnit($unitObj);

                    // image thumbs
                    $mediaManager = new RM_Media_Unit_Manager($unitObj);
                    $image = $imageFileModel->get($unitObj, RM_UnitMediaTypes::THUMBS)->current();
                    if (isset($image->filename)) {
                        $thumbnailImage = $mediaManager->getFileURL($image->filename, RM_Media_Image::get(RM_Media_Image::THUMB));
                    }

                    $url = RM_Environment::getInstance()->getRouter()->_('Unit', 'details', array('unit_id' => $unit["id"], 'isGroup'=>$isGroup, 'index2'=>true));
                    ?>
                    <table width="10" border="0" cellspacing="10" align="left">
                        <tr>
                            <td>
                                <a href="javascript:void(0)" onclick='RM_doShadowBox("<?php echo $url ?>", "", 800, 500, "iframe")' >
                                    <img src="<?php echo $thumbnailImage;?>" border="0">
                                </a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <center><?php echo $unitObj['name'];?></center>
                            </td>
                        </tr>
                    </table>
                    <?php
                }
                ?>
            </div>
        </fieldset>
    </div>
</div>